﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApMultipleLocationsManipulationCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CApMultipleLocationsManipulationCmd : TxButtonCommand
{
  private CApMultipleLocationsManipulationEnabler _enabler;
  private const string _STRING_TABLE_LOCATION = "DnProcessSimulateCommands.MultipleLocationsManipulation.MlmStringTable";
  private TxForm _mlmForm;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("LocationManipulator");

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;

  public CApMultipleLocationsManipulationCmd()
  {
    this._enabler = new CApMultipleLocationsManipulationEnabler();
  }

  public virtual bool Licensed => TxCommandLicenser.MultipleLocationsManipulationLicense;

  public virtual void Execute(object cmdParams)
  {
    if (!this._enabler.Enable || this._mlmForm != null)
      return;
    Cursor current = Cursor.Current;
    try
    {
      Cursor.Current = Cursors.WaitCursor;
      this._mlmForm = ((Collection<ITxObject>) this._enabler.GetSelectedLocations(this._enabler.GetSelectedLocationsAndOperationsList())).Count != 1 ? (TxForm) new CCUiMlmMultipleLocationsManipulationDlg() : (TxForm) new CCUiMlmSingleLocationManipulationDlg();
      ((Form) this._mlmForm).FormClosed += new FormClosedEventHandler(this._mlmForm_FormClosed);
      TxApplication.ApplicationEvents.Exiting += new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
      ((Control) this._mlmForm).Show();
    }
    catch (Exception ex)
    {
      int num = (int) TxMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    finally
    {
      Cursor.Current = current;
    }
  }

  private void ApplicationEvents_Exiting(object sender, TxApplication_ExitingEventArgs args)
  {
    if (this._mlmForm == null)
      return;
    ((Form) this._mlmForm).Close();
  }

  private void _mlmForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    this._mlmForm = (TxForm) null;
    TxApplication.ApplicationEvents.Exiting -= new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
  }

  public virtual string Bitmap => "MultipleLocationsManipulation.multiplelocationsmanipulation.bmp";

  public virtual string LargeBitmap
  {
    get => "MultipleLocationsManipulation.multiplelocationsmanipulation_LARGE.png";
  }

  public virtual string Category
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.MultipleLocationsManipulation.MlmStringTable", ((object) this).GetType().Assembly).GetString("MULTIPLE_LOCATIONS_MANIPULATION_CATEGORY");
    }
  }

  public virtual string Description
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.MultipleLocationsManipulation.MlmStringTable", ((object) this).GetType().Assembly).GetString("MULTIPLE_LOCATIONS_MANIPULATION_DESCRIPTION");
    }
  }

  public virtual string Name
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.MultipleLocationsManipulation.MlmStringTable", ((object) this).GetType().Assembly).GetString("MULTIPLE_LOCATIONS_MANIPULATION_NAME");
    }
  }

  public virtual string Tooltip
  {
    get
    {
      return new ResourceManager("DnProcessSimulateCommands.MultipleLocationsManipulation.MlmStringTable", ((object) this).GetType().Assembly).GetString("MULTIPLE_LOCATIONS_MANIPULATION_TOOLTIP");
    }
  }
}
